#include "HitsEvent.h"
#include <iostream>
#include <vector>
using namespace std;

HitsEvent::HitsEvent(const vector<float> fx, vector<float> fy, vector<float> fz, vector<float> fe)
{
    fx_ = fx;
    fy_ = fy;
    fz_ = fz;
    fe_ = fe;
    if (fx.size() == fy.size() && fy.size() == fz.size() && fz.size() == fe.size())
    {
        num_of_hits = fx.size();
    }
    else
    {
        cout << "WARNING: Inconsistent Number of Elements!!!" << endl;
    }
}

int HitsEvent::getNumOfHits()
{
    return num_of_hits;
}

vector<float> HitsEvent::getFx()
{
    return fx_;
}

vector<float> HitsEvent::getFy()
{
    return fy_;
}

vector<float> HitsEvent::getFz()
{
    return fz_;
}

vector<float> HitsEvent::getFe()
{
    return fe_;
}

float HitsEvent::getTotalEnergy()
{
    float totalEnergy = 0.;
    for (int i=0; i < fe_.size(); i++)
    {
        totalEnergy += fe_[i];
    }
    return totalEnergy;
}

void HitsEvent::show(int hit_id)
{
    if (hit_id < num_of_hits)
    {
        cout << "hit_" << hit_id << ", position:(" 
        << fx_[hit_id] << ", " << fy_[hit_id] << ", " << fz_[hit_id] 
        << "), energy: " << fe_[hit_id] << endl;
    }
    else
    {
        cout << "ERROR: Hit_id Cross the Border!!! The Number of Hits is: " << num_of_hits << endl; 
    }
}

void HitsEvent::showVertex()
{
    cout << "Vertex: (" << fx_[0] << ", " << fy_[0] << ", " << fz_[0] << ")" << endl;
    float PriDirection[3];
	PriDirection[0] = fx_[1] - fx_[0];
	PriDirection[1] = fy_[1] - fy_[0];
	PriDirection[2] = fz_[1] - fz_[0];

    float mag_a = 0;
    for (int l=0; l < 3; l++)
    {
        mag_a += pow(PriDirection[l], 2);
    }
    for (int h=0; h < 3; h++)
    {
        PriDirection[h] = PriDirection[h]/mag_a;
    }

    cout << "PriDirection: (" << PriDirection[0] << ", " << PriDirection[1] << ", " << PriDirection[1] << ")" << endl;
}